package appcenter

import (
	"fmt"
	"git.oschina.net/YPTArch/basic/libs/remote"
	"encoding/json"
	"git.oschina.net/YPTArch/usercenter/remoteserver/models"
	"git.oschina.net/YPTArch/usercenter/libs/data"
	"git.oschina.net/YPTArch/usercenter/config"
)

func RemoteGetApp(appId string ) (*models.Application){
	body, contentType, time, err := remote.HttpGet("http://"+config.GetAppConnAddress()+"http://192.168.1.100:8081/application/"+appId)
	fmt.Println(body, contentType, time, err)
	if err != nil {
		fmt.Println(err)
		return nil
	}
	temp := &data.Result{}
	err = json.Unmarshal([]byte(body), temp)
	fmt.Println(temp)
	if err != nil {
		fmt.Println(err)
		return nil
	}
	//当返回数据为空时
	if temp.Code!=200 || temp.Data==nil {
		return nil
	}
	fmt.Println(temp.Data)
	m:=temp.Data.(map[string]interface{})

	app:=new (models.Application)
   	app.AppId= m["AppId"].(string)
	app.AppName= m["AppName"].(string)
	app.AppDesc= m["AppDesc"].(string)

	return app
}